/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package edu.pku.sei.ocl.cst.impl;

import edu.pku.sei.ocl.cst.CSTPackage;
import edu.pku.sei.ocl.cst.HelperDefCS;
import edu.pku.sei.ocl.cst.OCLExpressionCS;
import edu.pku.sei.ocl.cst.SimpleNameCS;
import edu.pku.sei.ocl.cst.TypeCS;

import edu.pku.sei.ocl.cst.VariableCS;
import edu.pku.sei.ocl.evaluation.Context;
import edu.pku.sei.ocl.visitor.AbstractOCLVisitor;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Helper Def CS</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link edu.pku.sei.ocl.cst.impl.HelperDefCSImpl#getHelperName <em>Helper Name</em>}</li>
 *   <li>{@link edu.pku.sei.ocl.cst.impl.HelperDefCSImpl#getParameters <em>Parameters</em>}</li>
 *   <li>{@link edu.pku.sei.ocl.cst.impl.HelperDefCSImpl#getTypeCS <em>Type CS</em>}</li>
 *   <li>{@link edu.pku.sei.ocl.cst.impl.HelperDefCSImpl#getBody <em>Body</em>}</li>
 *   <li>{@link edu.pku.sei.ocl.cst.impl.HelperDefCSImpl#getHelperModifier <em>Helper Modifier</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class HelperDefCSImpl extends CSTNodeImpl implements HelperDefCS {
	/**
	 * The cached value of the '{@link #getHelperName() <em>Helper Name</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getHelperName()
	 * @generated
	 * @ordered
	 */
	protected SimpleNameCS helperName;

	/**
	 * The cached value of the '{@link #getParameters() <em>Parameters</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getParameters()
	 * @generated
	 * @ordered
	 */
	protected EList<VariableCS> parameters;

	/**
	 * The cached value of the '{@link #getTypeCS() <em>Type CS</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getTypeCS()
	 * @generated
	 * @ordered
	 */
	protected TypeCS typeCS;

	/**
	 * The cached value of the '{@link #getBody() <em>Body</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getBody()
	 * @generated
	 * @ordered
	 */
	protected OCLExpressionCS body;

	/**
	 * The default value of the '{@link #getHelperModifier() <em>Helper Modifier</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getHelperModifier()
	 * @generated
	 * @ordered
	 */
	protected static final String HELPER_MODIFIER_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getHelperModifier() <em>Helper Modifier</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getHelperModifier()
	 * @generated
	 * @ordered
	 */
	protected String helperModifier = HELPER_MODIFIER_EDEFAULT;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected HelperDefCSImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return CSTPackage.Literals.HELPER_DEF_CS;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public SimpleNameCS getHelperName() {
		return helperName;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetHelperName(SimpleNameCS newHelperName,
			NotificationChain msgs) {
		SimpleNameCS oldHelperName = helperName;
		helperName = newHelperName;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this,
					Notification.SET, CSTPackage.HELPER_DEF_CS__HELPER_NAME,
					oldHelperName, newHelperName);
			if (msgs == null)
				msgs = notification;
			else
				msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setHelperName(SimpleNameCS newHelperName) {
		if (newHelperName != helperName) {
			NotificationChain msgs = null;
			if (helperName != null)
				msgs = ((InternalEObject) helperName).eInverseRemove(this,
						EOPPOSITE_FEATURE_BASE
								- CSTPackage.HELPER_DEF_CS__HELPER_NAME, null,
						msgs);
			if (newHelperName != null)
				msgs = ((InternalEObject) newHelperName).eInverseAdd(this,
						EOPPOSITE_FEATURE_BASE
								- CSTPackage.HELPER_DEF_CS__HELPER_NAME, null,
						msgs);
			msgs = basicSetHelperName(newHelperName, msgs);
			if (msgs != null)
				msgs.dispatch();
		} else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET,
					CSTPackage.HELPER_DEF_CS__HELPER_NAME, newHelperName,
					newHelperName));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<VariableCS> getParameters() {
		if (parameters == null) {
			parameters = new EObjectContainmentEList<VariableCS>(
					VariableCS.class, this,
					CSTPackage.HELPER_DEF_CS__PARAMETERS);
		}
		return parameters;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public TypeCS getTypeCS() {
		return typeCS;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetTypeCS(TypeCS newTypeCS,
			NotificationChain msgs) {
		TypeCS oldTypeCS = typeCS;
		typeCS = newTypeCS;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this,
					Notification.SET, CSTPackage.HELPER_DEF_CS__TYPE_CS,
					oldTypeCS, newTypeCS);
			if (msgs == null)
				msgs = notification;
			else
				msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setTypeCS(TypeCS newTypeCS) {
		if (newTypeCS != typeCS) {
			NotificationChain msgs = null;
			if (typeCS != null)
				msgs = ((InternalEObject) typeCS)
						.eInverseRemove(this, EOPPOSITE_FEATURE_BASE
								- CSTPackage.HELPER_DEF_CS__TYPE_CS, null, msgs);
			if (newTypeCS != null)
				msgs = ((InternalEObject) newTypeCS)
						.eInverseAdd(this, EOPPOSITE_FEATURE_BASE
								- CSTPackage.HELPER_DEF_CS__TYPE_CS, null, msgs);
			msgs = basicSetTypeCS(newTypeCS, msgs);
			if (msgs != null)
				msgs.dispatch();
		} else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET,
					CSTPackage.HELPER_DEF_CS__TYPE_CS, newTypeCS, newTypeCS));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public OCLExpressionCS getBody() {
		return body;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetBody(OCLExpressionCS newBody,
			NotificationChain msgs) {
		OCLExpressionCS oldBody = body;
		body = newBody;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this,
					Notification.SET, CSTPackage.HELPER_DEF_CS__BODY, oldBody,
					newBody);
			if (msgs == null)
				msgs = notification;
			else
				msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setBody(OCLExpressionCS newBody) {
		if (newBody != body) {
			NotificationChain msgs = null;
			if (body != null)
				msgs = ((InternalEObject) body)
						.eInverseRemove(this, EOPPOSITE_FEATURE_BASE
								- CSTPackage.HELPER_DEF_CS__BODY, null, msgs);
			if (newBody != null)
				msgs = ((InternalEObject) newBody)
						.eInverseAdd(this, EOPPOSITE_FEATURE_BASE
								- CSTPackage.HELPER_DEF_CS__BODY, null, msgs);
			msgs = basicSetBody(newBody, msgs);
			if (msgs != null)
				msgs.dispatch();
		} else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET,
					CSTPackage.HELPER_DEF_CS__BODY, newBody, newBody));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getHelperModifier() {
		return helperModifier;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setHelperModifier(String newHelperModifier) {
		String oldHelperModifier = helperModifier;
		helperModifier = newHelperModifier;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET,
					CSTPackage.HELPER_DEF_CS__HELPER_MODIFIER,
					oldHelperModifier, helperModifier));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd,
			int featureID, NotificationChain msgs) {
		switch (featureID) {
		case CSTPackage.HELPER_DEF_CS__HELPER_NAME:
			return basicSetHelperName(null, msgs);
		case CSTPackage.HELPER_DEF_CS__PARAMETERS:
			return ((InternalEList<?>) getParameters()).basicRemove(otherEnd,
					msgs);
		case CSTPackage.HELPER_DEF_CS__TYPE_CS:
			return basicSetTypeCS(null, msgs);
		case CSTPackage.HELPER_DEF_CS__BODY:
			return basicSetBody(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
		case CSTPackage.HELPER_DEF_CS__HELPER_NAME:
			return getHelperName();
		case CSTPackage.HELPER_DEF_CS__PARAMETERS:
			return getParameters();
		case CSTPackage.HELPER_DEF_CS__TYPE_CS:
			return getTypeCS();
		case CSTPackage.HELPER_DEF_CS__BODY:
			return getBody();
		case CSTPackage.HELPER_DEF_CS__HELPER_MODIFIER:
			return getHelperModifier();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
		case CSTPackage.HELPER_DEF_CS__HELPER_NAME:
			setHelperName((SimpleNameCS) newValue);
			return;
		case CSTPackage.HELPER_DEF_CS__PARAMETERS:
			getParameters().clear();
			getParameters().addAll((Collection<? extends VariableCS>) newValue);
			return;
		case CSTPackage.HELPER_DEF_CS__TYPE_CS:
			setTypeCS((TypeCS) newValue);
			return;
		case CSTPackage.HELPER_DEF_CS__BODY:
			setBody((OCLExpressionCS) newValue);
			return;
		case CSTPackage.HELPER_DEF_CS__HELPER_MODIFIER:
			setHelperModifier((String) newValue);
			return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
		case CSTPackage.HELPER_DEF_CS__HELPER_NAME:
			setHelperName((SimpleNameCS) null);
			return;
		case CSTPackage.HELPER_DEF_CS__PARAMETERS:
			getParameters().clear();
			return;
		case CSTPackage.HELPER_DEF_CS__TYPE_CS:
			setTypeCS((TypeCS) null);
			return;
		case CSTPackage.HELPER_DEF_CS__BODY:
			setBody((OCLExpressionCS) null);
			return;
		case CSTPackage.HELPER_DEF_CS__HELPER_MODIFIER:
			setHelperModifier(HELPER_MODIFIER_EDEFAULT);
			return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
		case CSTPackage.HELPER_DEF_CS__HELPER_NAME:
			return helperName != null;
		case CSTPackage.HELPER_DEF_CS__PARAMETERS:
			return parameters != null && !parameters.isEmpty();
		case CSTPackage.HELPER_DEF_CS__TYPE_CS:
			return typeCS != null;
		case CSTPackage.HELPER_DEF_CS__BODY:
			return body != null;
		case CSTPackage.HELPER_DEF_CS__HELPER_MODIFIER:
			return HELPER_MODIFIER_EDEFAULT == null ? helperModifier != null
					: !HELPER_MODIFIER_EDEFAULT.equals(helperModifier);
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy())
			return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (helperModifier: "); //$NON-NLS-1$
		result.append(helperModifier);
		result.append(')');
		return result.toString();
	}

	@Override
	public Object accept(AbstractOCLVisitor v, Context env, Object... argv) {
		if (argv == null || argv.length == 0) {
			return v.visitHelperDefCS(this, env);
		} else {
			return v.visitHelperDefCS(this, env, argv);
		}
	}
} //HelperDefCSImpl
